/*
  This file is a part of hashutils package.
  (c) 2004 Zeljko Vrba <zvrba@globalnet.hr>

  Permission is hereby granted, free of charge, to any person obtaining
  a copy of this software and associated documentation files (the
  "Software"), to deal in the Software without restriction, including
  without limitation the rights to use, copy, modify, merge, publish,
  distribute, sublicense, and/or sell copies of the Software, and to
  permit persons to whom the Software is furnished to do so, subject to
  the following conditions:

  The above copyright notice and this permission notice shall be
  included in all copies or substantial portions of the Software.

  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
  EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
  IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
  CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
  TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
  SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
#ifndef CDT_LINE_H__
#define CDT_LINE_H__

#include <stddef.h>
#include <cdt.h>
#include <sfio.h>
#include <vmalloc.h>

/** Line hash structure, CDT and vmalloc discipline. */
struct line {
	Dtlink_t _l;				/* link */
	unsigned int n;				/* line number */
	char h[1];					/* hash */
};

/*
  Line discipline for containers. Note that line must ALWAYS be allocated
  before inserted in the container. The container make and free functions
  are always set to NULL.
*/
extern Dtdisc_t Cdt_LineDiscipline;

/*
  Ugly, but portable way to calculate minimum allocation size given
  the hash length in bytes (we have to obey struct member alignment).
  h begins at some offset; adding hlen to that offset gives the necessary
  size of struct.
*/
#define LINESZ(hlen) (offsetof(struct line, h) + hlen)

/* Read file lines into set. */
Dt_t *LineSet_read_file(Sfio_t *f, int halg);
extern int LineSet_report_collisions;
extern Vmalloc_t *LineSet_vmpool;
extern Vmdisc_t *Vmdcmmap;


#endif /* CDT_LINE_H__ */
